<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
<img id="img1" src="https://tse3-mm.cn.bing.net/th/id/OIP-C.qH7Hv9LY6MWPcCfN77yB8AAAAA?w=192&h=193&c=7&r=0&o=5&dpr=1.25&pid=1.7" alt="">
<img id="img2" src="https://tse3-mm.cn.bin666g.net/th/id/OIP-C.qH7Hv9LY6MWPcCfN77yB8AAAAA?w=192&h=193&c=7&r=0&o=5&dpr=1.25&pid=1.7" alt="">

<script>
    const img1 = document.getElementById("img1")
    const img2 = document.getElementById("img2")

    window.onload = function(){
        console.log('页面加载完毕');
    }

    img1.onload = function(){
        console.log('图片1加载完成');
    }

    img2.onerror = function(){
        console.log('图片2加载错误');
    }

    window.addEventListener("beforeunload" , (event) => {
        event.returnValue = "有位保存的值，确定要离开吗？"
    });

</script>

</body>
</html>